<?php
/**
 * Created by PhpStorm.
 * User: Inhere
 * Date: 15-4-1
 * Time: 上午10:08
 * Used: zui 垂直菜单
 * file: VerticalMenu.php
 */

namespace ulue\ext\zui;

use ulue\libs\front\Element;

class VerticalMenu extends Nav
{
///////////////////////// tag nav /////////////////////////
    /**
     * 垂直菜单 宽度
     */
    public $width = '200px';

    /**
     * @var array
     */
    public $attrs = [
        'class'       => 'menu',
        'data-toggle' => 'menu',
    ];

///////////////////////// main nav tag [ tag ul] /////////////////////////

    // 主导航列表
    /**
     * @var array
     */
    public $mainNav = [];

    /**
     * @var array
     */
    public $mainNavAttrs = [
        'class'       => 'nav nav-primary',
    ];

///////////////////////// custom tag [ tag button] /////////////////////////

    /**
     * @var array
     */
    public $buttonGroup = [];

    public function __construct()
    {
        $this->mainNav         = $this->mainNav();
        $this->buttonGroup    = $this->buttonGroup();
        // add custom ...
    }

    /**
     * @return string
     */
    public function beginExecute()
    {
        // tag nav
        $nav = new Element('nav',null,$this->attrs);
        $nav->addStyle('width', $this->width);

        if ($btns = $this->buttonGroup) {

            foreach ($btns as $tag) {
                $b = new Element('button', $tag['text'], $tag['attrs']);

                if (isset($tag['child'])) {

                    foreach ($tag['child'] as $val) {
                        $child = new Element($val['name'],null, $val['attrs']);

                        $b->setChildPosition(Element::BEFORE_TEXT)->addChild($child);
                    }
                }

                $nav->addChild($b);
            }
        }

        if ($this->mainNav) {
            $mainNav = $this->createUlElement($this->mainNav, $this->mainNavAttrs);
            $nav->addChild($mainNav);
        }

        return $nav->getString();
    }

    /**
     * @return array
     */
    protected function buttonGroup()
    {
        /*
          <button class="><i class="icon-edit"></i> CREATE</button>
        <button class="btn"><i class="icon-cloud-upload"></i> UPLOAD</button>
        */
        return [
            [
                'text' => ' CREATE',
                'attrs' => ['class'=>'btn btn-primary'],
                'child' =>[
                    [
                        'name' => 'i',
                        'position' => Element::BEFORE_TEXT,
                        'attrs' => ['class'=>'icon-edit']
                    ]
                ]
            ],
            [
                'text' => ' UPLOAD',
                'attrs' => ['class'=>'btn'],
                'child' =>[
                    [
                        'name'  => 'i',
                        'position'  => Element::BEFORE_TEXT,
                        'attrs' => ['class'=>'icon-cloud-upload']
                    ]
                ]
            ],
        ];

    }

    /**
     * @return array
     */
    protected function mainNav()
    {
        //  setting
        return [

            'index'    => [
                'text'  => '链接',
                'href'  => \Ioc::get('app.uri')->get('index.path'),
                'icon'  => 'icon-home',
                'attrs' => [],
            ],
            'site/more'    => [
                'text'  => '更多',
                'href'  => '' ,
                'icon'  => 'icon-inbox',
                // 'attrs' => [],
                'submenu' => [
                    [
                        'text'  => 'GIT',
                        'href'  => 'http://www.higit.com/',
                        'icon'  => 'icon-stack',
                        'attrs'  => ['target'=>'_blank'],
                    ],
                    [
                        'text'  => 'FileManager',
                        'href'  => 'http://www.kode.com/',
                        'icon'  => 'icon-archive',
                        'attrs'  => ['target'=>'_blank'],
                    ],
                ],
            ],
        ];
    }


}// end class VerticalMenu